package APPyanghuanyu.reflect;

import APPyanghuanyu.Person.Person;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;

public class ReflectDome3 {
    public static void main(String[] args) throws Exception {
        //1.获取Person的Class对象
        Class personClass = Person.class;

        //获取构造方法们
        //Constructor:构造方法
        //  主要作用： 创建对象  newInstance(Object...initargs)

        Constructor constructor = personClass.getConstructor(String.class, int.class);
        System.out.println(constructor);
        Object obj = constructor.newInstance("张三", 23);
        System.out.println(obj);

        System.out.println("------------------");
        //构造空参对象
        Constructor constructor1 = personClass.getConstructor();
        System.out.println(constructor1);
        Object obj1 = constructor1.newInstance();
        System.out.println(obj1);
        //用Class对象的newInstance()构造空参对象
        Object o = personClass.newInstance();
        System.out.println(o);


    }
}
